mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
Loading...
Searching...
No Matches
throw.h
Go to the documentation of this file.
1
30
31#ifndef MRB_THROW_H
32#define MRB_THROW_H
33
34#if defined(MRB_USE_CXX_ABI) && !defined(__cplusplus)
35# error Trying to use C++ exception handling in C code
36#endif
37
38#if defined(MRB_USE_CXX_EXCEPTION)
39
40# if defined(__cplusplus)
41
42#define MRB_TRY(buf) try {
43#define MRB_CATCH(buf) } catch(mrb_jmpbuf *e) { if (e != (buf)) { throw e; }
44#define MRB_END_EXC(buf) }
45
46#define MRB_THROW(buf) throw(buf)
47typedef void *mrb_jmpbuf_impl;
48
49# else
50# error "need to be compiled with C++ compiler"
51# endif /* __cplusplus */
52
53#else
54
55#include <setjmp.h>
56
57#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
58#define MRB_SETJMP _setjmp
59#define MRB_LONGJMP _longjmp
60#elif defined(__MINGW64__) && !defined(_M_ARM64) && defined(__GNUC__) && __GNUC__ >= 4
61#define MRB_SETJMP __builtin_setjmp
62#define MRB_LONGJMP __builtin_longjmp
63#else
64#define MRB_SETJMP setjmp
65#define MRB_LONGJMP longjmp
66#endif
67
68#define MRB_TRY(buf) if (MRB_SETJMP((buf)->impl) == 0) {
69#define MRB_CATCH(buf) } else {
70#define MRB_END_EXC(buf) }
71
72#define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1);
73#define mrb_jmpbuf_impl jmp_buf
74
75#endif
76
77struct mrb_jmpbuf {
78 mrb_jmpbuf_impl impl;
79};
80
81#endif /* MRB_THROW_H */
Definition throw.h:77